In Ruby, I use function .pack("H*")].pack("m0") to encode a hex message string to base64 string.
ex.
msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
msg_hex.pack("H*")].pack("m0") => gwiGKDEDFZE0XwEBAQIGY2AqBuMAAAAA75NODFsp5Q4AAAAAAAAAAAAAAxAAAAAATwQBAAABAAA=
In Javascript, I am looking for an equivalent method to convert message to 64base message. Some answers tell useing Buffer.from(msg_hex).toString('base64'), but the result is different.
const msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
Buffer.from(msg_hex).toString('base64') // => ODMwODg2MjgzMTAzMTU5MTM0NUYwMTAxMDEwMjA2NjM2MDJBMDZFMzAwMDAwMDAwRUY5MzRFMEM1QjI5RTUwRTAwMDAwMDAwMDAwMDAwMDAwMzEwMDAwMDAwMDA0RjA0MDAwMDAwMDEwMDAw
what is the equivalent method for .pack("H*")].pack("m0") of Ruby in Javascript?
You was nearly there with what you supplied.
You just forgot to tell Buffer.from what you was supplying, as default if you send a string it's just going to store it as a string. But what you wanted was to decode the source as hex and then store as binary.
So doing ->
Buffer.from(msg_hex, 'hex').toString('base64')
IOW: you just missed the second parameter hex..